<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="artDialog/skins/default.css"
	type="text/css"></link>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="artDialog/artDialog.min.js"></script>
<script type="text/javascript" src="artDialog/jquery.artDialog.min.js"></script>
<script type="text/javascript" src="artDialog/artDialog.plugins.min.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/highcharts.js"></script>
<script type="text/javascript" src="js/highcharts-3d.js"></script>
<script type="text/javascript" src="js/exporting.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
  $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
  $(".tip").fadeOut(200);
});

  $(".sure").click(function(){
  $(".tip").fadeOut(100);
});

  $(".cancel").click(function(){
  $(".tip").fadeOut(100);
});
$.post("group!findGroupList.action",function(data){
	var groups = eval("("+data+")");
	if(groups!=null){
	var html = "";

		for(var i = 0 ; i < groups.length;i++){
			html+="<tr><td>"+groups[i].id+"</td><td>"+groups[i].name+"</td><td>"+(groups[i]._user==null? "无":groups[i]._user.name)+"</td><td>"+groups[i].createTime+"</td><td>"+groups[i].userCount+"</td> <td><a href=\"javascript:void(0)\" onclick='model_eidt("+groups[i].purview.id+")' >权限</a>     <a href=\"javascript:void(0)\" onclick='group_update("+groups[i].id+",\""+groups[i].name+"\")' >修改</a>     <a href=\"javascript:void(0)\" onclick='group_del("+groups[i].id+")' >删除</a></td></tr>";
		}
		$("#group_list").html(html);
		$('#group_list tr:odd').addClass('odd');
		
	}
});
});
function group_del(id){
	okCancelAlert("删除用户组","确定删除此用户组?",function(){
		$.post("group!deleteGroup.action",{gid:id},function(data){
			var json = eval("("+data+")");
			
			if(json.code==1){
				defaultAlert("删除用户组","删除成功");
				location.href="group.html";
			}else if(json.code==0){
				defaultAlert("删除用户组","删除失败");
			}else{
				defaultAlert("删除用户组","未知错误");
			}
		});
	},function(){});}
function group_update(id,name){
	art.dialog({title:"修改用户组名称",content:"<input style='background-color:#eeeeee' type='text' id='in_group_name' value='"+name+"' />",lock:true,fixed:true,okValue:'修改',cancelValue:'取消',ok:function(){
		var gname = document.getElementById("in_group_name");
		if(gname.value==""){
			gname.select();
			gname.focus();
			this.shake();
			return false;
		}
		$.post("group!updateGroupName.action",{gid:id,"name":gname.value},function(data){
			var json = eval("("+data+")");
			if(json.code==1){
				defaultAlert("修改用户组","修改成功");
				location.href="group.html";
			}else{
					defaultAlert("修改用户组","修改失败");
			}
		});
	},cancel:function(){}});
}
function model_eidt(id){
	$.post("purview!findList.action",function(data){
		var models = eval("("+data+")");
		var html="";
		
		$.post("purview!findListByPId.action",{"id":id},function(data){
			var currentModels=eval("("+data+")");
			
			for(var i =0;i<models.length;i++){
				var flag = false;
				for(var x=0;x<currentModels.length;x++){
						if(models[i].id==currentModels[x].id){
							flag = true;
							break;
						}
				}
			html+="<input type='checkbox' class='cbo_model' id='model_"+models[i].id+"' "+(flag ==true ? "checked='checked'" :"")+"/>"+models[i].name;
			if((i+1)%3==0){
				html+="<br>";
			}
		}
		art.dialog({title:"权限配置",content:html,lock:true,fixed:true,okValue:"确定",cancelValue:"取消",ok:function(){
			var ids="";
			$(".cbo_model").each(function(){
				if($(this).attr("checked")){
				
					ids+=$(this).attr("id").substring(6,$(this).attr("id").length)+",";
				}
				
			});
			if(ids.length>0){
				ids=ids.substring(0,ids.length-1);
				$.post("purview!updatePurview.action",{"id":id,"mid":ids},function(data){
					var json = eval("("+data+")");
					if(json.code==1){
						defaultAlert("权限配置","修改成功");
					}else{
						defaultAlert("权限配置","修改失败");
					}
				});
				
			}else{
				defaultAlert("权限配置","至少选中一项权限");
			}
		},cancel:function(){}});
		});
		
	});
}
function group_add(){
$.post("purview!findList.action",function(data){
		var models = eval("("+data+")");
		var html="<label>用户组名称:</label><input type='text' id='add_group_name' style='background-color:#eeeeee' /><br>";
		for(var i = 0 ; i<models.length;i++){
			html+="<input type='checkbox' class='cbo_model' id='model_"+models[i].id+"' />"+models[i].name;
			if((i+1)%3==0){
				html+="<br>";
			}
		}
		art.dialog({title:"添加用户组",lock:true,fixed:true,content:html,okValue:"添加",cancelValue:"取消",cancel:function(){},ok:function(){
			var name = document.getElementById("add_group_name");
			if(name.value==""){
				name.select();
				name.focus();
				this.shake();
				return false;
			}
			var ids="";
			$(".cbo_model").each(function(){
				if($(this).attr("checked")){
				
					ids+=$(this).attr("id").substring(6,$(this).attr("id").length)+",";
				}
				
			});
			if(ids.length>0){
				ids=ids.substring(0,ids.length-1);
				$.post("group!addGroup.action",{"name": name.value,"mid" : ids},function(data){
					var json = eval("("+data+")");
					if(json.code==1){
						defaultAlert("添加用户组","添加成功");
						location.href="group.html";
					}else{
						defaultAlert("添加用户组","添加失败");
					}
				});
				
			}else{
				defaultAlert("权限配置","至少选中一项权限");
			}
			
		}});
	});
}

function bingtu(){
	
	window.location.href="bing.html";
	
}
</script>


</head>


<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">系统管理</a></li>
    <li><a href="#">用户组设置</a></li>
    </ul>
    </div>
    
    <div class="rightinfo">
    
    <div class="tools">
    
    	<ul class="toolbar">
        <li onclick="group_add()"><span><img src="images/t01.png" /></span>添加</li>
        <!--  <li class="click"><span><img src="images/t02.png" /></span>修改</li>
        <li><span><img src="images/t03.png" /></span>删除</li> -->
        <li  onclick="bingtu()"><span><img src="images/t04.png" /></span>统计</li> 
        </ul>
        
        
        <ul class="toolbar1">
      <!--   <li><span><img src="images/t05.png" /></span>设置</li> -->
        </ul>
    
    </div>
    
    
    <table class="tablelist">
    	<thead>
    	<tr>
        <th>编号</th>
        <th>用户组名称</th>
        <th>创建人</th>
        <th>创建时间</th>
        <th>用户组人数</th>
        <th>操作</th>
        </tr>
        </thead>
        <tbody id="group_list">
       
        </tbody>
    </table>
    
   
   
    
    

    <script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
	</script>

</body>
</html>
